package com.cxx.purchasecharge.dal;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.cxx.purchasecharge.core.model.OrderStatusCode;
import com.cxx.purchasecharge.core.model.persistence.Order;
import com.cxx.purchasecharge.dal.common.GenericCRUDDao;

@Transactional
public interface OrderDao extends GenericCRUDDao <Order, Long>, OrderDaoPlus
{

    @Query (value = "select o from Order o where o.customer.shortName=?1")
    public List <Order> findByCustomerName (String customerName);

    @Query (value = "select o from Order o where o.customer.id=?1")
    public List <Order> findByCustomerId (long customerId);

    @Query (value = "select o from Order o where o.statusCode=?1")
    public List <Order> findByOrderStatusCode (OrderStatusCode statusCode);

    @Query (value = "select o from Order o where o.userSigned=?1")
    public List <Order> findByUserSigned (long userId);

    @Modifying
    @Query ("update Order o set o.statusCode = ?1, o.comment = ?2 where o.id = ?3")
    public int updateStatus (OrderStatusCode statusCode, String comment, long id);

    @Modifying
    @Query ("update Order o set o.profit = ?1 where o.id = ?2")
    public int updateProfit (float profit, long id);
    
    @Modifying
    @Query ("update Order o set o.receivable = ?1 where o.id = ?2")
    public int updateReceivable (float receivable, long id);
}
